<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>阳光成单系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
<link rel="stylesheet" href="js/layui/css/layui.css" media="all">
<script type="text/javascript" src="js/layui/layui.js"></script>
</head>

<body>
	<div class="x-body">
		<form class="layui-form" id="product-edit-form" onsubmit="return false"><!-- 默认取消form表单提交事件 -->
			<div class="layui-form-item">
                    <label for="cname"  class="layui-form-label">
                        	<span class="x-red">*</span>产品ID
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="productId" name="productId" required="" lay-verify="required"
                        autocomplete="off" readonly="" class="layui-input">
                    </div>
             </div>
			<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
					class="x-red">*</span>产品名称
				</label>
				<div class="layui-input-inline">
					<input name="productName" id="productName" value="" class="layui-input"
					placeholder="填写产品名称">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
					class="x-red">*</span>点击上传
				</label>
				<button type="button" class="layui-btn" id="product">
					<i class="layui-icon">&#xe67c;</i>上传图片
				</button>
			</div>
			<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
					class="x-red">*</span>产品图片
				</label>
				<div class="layui-input-inline">
					<div class="site-demo-upbar">
						<img id="imgFace" style="width: 120px" src="" />
					</div>
				</div>
			</div>
			
		<div class="layui-form-item">
			<label for="link" class="layui-form-label"> <span
				class="x-red">*</span>图片路径
			</label>
			<div class="layui-input-inline">
				<input name="picName" id="picName" value="" class="layui-input"
				placeholder="图片路径自动生成">
			</div>
		</div>
		<div class="layui-form-item">
			<label for="link" class="layui-form-label"> <span
				class="x-red">*</span>产品市场价
			</label>
			<div class="layui-input-inline">
				<input name="productPrice" id="productPrice" value="" class="layui-input"
				placeholder="请输入市场价">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label for="link" class="layui-form-label"> <span
				class="x-red">*</span>产品售价
			</label>
			<div class="layui-input-inline">
				<input name="salePrice" id="salePrice" value="" class="layui-input"
				placeholder="请输入产品售价">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label for="link" class="layui-form-label"> <span
				class="x-red">*</span>设计理念
			</label>
			<div class="layui-input-inline">
			<textarea required lay-verify="required" name="productTexture" id="productTexture" class="layui-textarea" placeholder="请输入产品的设计理念"></textarea>
			</div>
		</div>
			<div class="layui-form-item">
					<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品系列
					</label>
					<div class="layui-input-inline">
						<select id="productCategoryId" name="productCategoryId">
							<option id="testop" value=""></option>
						</select>
					</div>
				</div>
				
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品品牌
					</label>
					<div class="layui-input-inline">
						<select name="productBrand" id="productBrand">
							<option value="">请选择品牌</option>
							<option value="莱绅通灵">莱绅通灵</option>
						</select>				
					</div>
				</div>
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品尺寸
					</label>
					<div class="layui-input-inline">
						<select name="productSize">
							<option value="">请选择尺寸</option>
							<option value="60分">60分</option>
							<option value="50分">50分</option>
							<option value="30分">30分</option>
							<option value="20分">20分</option>
						</select>				
					</div>
				</div>
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品颜色
					</label>
					<div class="layui-input-inline">
					<select name="productColor">
						<option value="">请选择颜色</option>
						<option value="H">H</option>
						<option value="F">F</option>
					</select>
					</div>
				</div>
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品净度
					</label>
					<div class="layui-input-inline">
					<select name="productNetDegree">
						<option value="">请选择净度</option>
						<option value="VVS">VVS</option>
						<option value="VS">VS</option>
					</select>
					</div>
				</div>
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>产品切工
					</label>
					<div class="layui-input-inline">
					<select name="productSpecification">
						<option id="productSpecification" value="">请选择切工</option>
						<option value="黄金">黄金</option>
						<option value="红金">红金</option>
						<option value="白金">白金</option>
					</select>
					</div>
				</div>
				<div class="layui-form-item">
				<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>是否定制
					</label>
					<div class="layui-input-inline">
						<select name="isCutomize">
							<option value="">是否定制</option>
							<option value="yes">yes</option>
						</select>
					</div>
				</div>					
				<div class="layui-form-item">
					<label for="link" class="layui-form-label"> <span
						class="x-red">*</span>选择材质
					</label>
					<div class="layui-input-inline">
						<select name="productMaterial" >
							<option value="">产品材质</option>
							<option value="钻石">钻石</option>
						</select>
					</div>
				</div>
					<div class="layui-form-item">
						<label for="L_repass" class="layui-form-label"> </label>
						<button class="layui-btn" lay-filter="add" onclick="editProduct()">修改</button>
					</div>
			</div>
		</form>
	</div>
	<script src="./lib/layui/layui.js" charset="utf-8">
		
	</script>
	<script src="./js/x-layui.js" charset="utf-8">
		
	</script>
	<script>
		var $ = null;
		var form = null;
		var layer = null;
		var upload = null;
		layui.use([ 'form', 'layer', 'upload' ], function() {
			$ = layui.jquery;
			form = layui.form;
			upload = layui.upload;
			layer = layui.layer;

			//执行实例,上传图片
			var uploadInst = upload.render({
				elem : '#product', 
				url : '../adminJson?reqName=upload', 
				acceptMime : 'images/*',
				done : function(res) {
					if (res.success) {
						$("#imgFace").attr("src", "../images/" + res.remark);
						$("#picName").val("images/" + res.remark);
						layer.msg("上传成功", {
							icon : 6,
							time : 1500
						});
					}
				},
				error : function() {
				}
			});
			$(function(){
				getProduct();
			});

		});
		//动态获取下拉框
		 function productcate(){
         	$.post("../adminProductCategory?reqName=getAllProductCate",{},function(res){
         		for(var i=0;i<res.length;i++){
         		$("#productCategoryId").append("<option value="+res[i].productSeriesId+">"+res[i].productSeriesName+"</option>");
         			form.render("select");
         		}
         	},"json");
         }
	 //根据id查询该Id的数据,目的是为了回显
        function getProduct(){
        	$.post("../adminProduct?reqName=getProductById",{
        		pId : sessionStorage.getItem("productId")
        	},function(res){
				$("#productId").val(res.productId);
        		$("#imgFace").attr("src", "../"+res.productPicture);
				$("#picName").val(res.productPicture);
				$("#productName").val(res.productName);
				$("#salePrice").val(res.salePrice);
				$("#productPrice").val(res.productPrice);
				$("#productTexture").val(res.productTexture);
				$("#testop").text(res.productSeriesName).attr("value",res.productCategoryId);
				productcate();
        	},"json");
        }
        
		
		//编辑产品
		function editProduct(){
			$.post("../adminProduct?reqName=editProduct",$("#product-edit-form").serialize(),function(res){
				if(res.success){
					layer.msg(res.message);
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
					parent.myPage();
				}else{
					layer.msg(res.message);
				}
			},"json");
        	
        }
	</script>

</body>

</html>